package com.soul.doc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.soul.common.msg.ApiResult;
import com.soul.doc.bean.dto.SingerAddDto;
import com.soul.doc.bean.dto.SingerSearchDto;
import com.soul.doc.bean.dto.SingerUpdateDto;
import com.soul.doc.bean.vo.SingerVo;
import com.soul.doc.service.SingerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.soul.common.controller.BaseController;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sws
 * @since 2023-11-19 11:05:21
 */
@RestController
@RequestMapping("/singer")
@Api(value="singer", tags = "歌手接口")
public class SingerController extends BaseController {

    @Autowired
    private SingerService singerService;

    @GetMapping("/{page}/{size}/list/ext")
    @ApiOperation(value = "获取歌手分页")
    public ApiResult<IPage<SingerVo>> queryList(@PathVariable("page") Integer page, @PathVariable("size") Integer size, SingerSearchDto searchDto){
        IPage<SingerVo> IPage = this.singerService.querySingerList(page, size, searchDto);
        return ApiResult.success(IPage);
    }

    @GetMapping("/list/ext")
    @ApiOperation(value = "获取歌手")
    public ApiResult<List<SingerVo>> queryList(){
        List<SingerVo> IPage = this.singerService.querySingerListAll();
        return ApiResult.success(IPage);
    }


    @GetMapping("/{id}/info/ext")
    @ApiOperation(value = "获取歌手详细信息")
    public ApiResult<SingerVo> getSinger(@PathVariable Long id){
        SingerVo dictTypeInfo = this.singerService.getSinger(id);
        return ApiResult.success(dictTypeInfo);
    }
    /**
     * 新增歌手
     * @param addDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增歌手")
    public ApiResult<?> add(@RequestBody SingerAddDto addDto){
        this.singerService.addSinger(addDto);
        return ApiResult.success();
    }

    /**
     * 修改歌手
     * @param updateDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改歌手")
    public ApiResult<?> add(@RequestBody SingerUpdateDto updateDto){
        this.singerService.updateSinger(updateDto);
        return ApiResult.success();
    }

    /**
     * 删除歌手
     * @param id
     * @return
     */
    @DeleteMapping("/{id}/del")
    @ApiOperation(value = "删除歌手，根据id")
    public ApiResult<?> delete(@PathVariable("id") Long id){
        this.singerService.deleteSinger(Collections.singletonList(id));
        return ApiResult.success();
    }

    @GetMapping("/{page}/{size}/hot/list/ext")
    @ApiOperation(value = "获取热门歌手")
    public ApiResult<IPage<SingerVo>> queryHotList(@PathVariable("page") Integer page, @PathVariable("size") Integer size, SingerSearchDto searchDto){
        IPage<SingerVo> IPage = this.singerService.queryHotSingerList(page, size, searchDto);
        return ApiResult.success(IPage);
    }
}
